package com.zgjkhis.modules.statistics.rest;

import com.zgjkhis.modules.security.security.LoginUserUtil;
import com.zgjkhis.modules.statistics.req.StoreDrugRequest;
import com.zgjkhis.modules.statistics.resp.StoreDrugResp;
import com.zgjkhis.modules.statistics.service.StoreDrugService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author yxl
 * @Description
 * @Date 2021/12/23 18:54
 **/
@RestController
@Api(tags = "运营数据：药房药品")
@RequestMapping("drugStatistics")
public class StoreDrugController {

    @Resource
    private StoreDrugService service;

//    @Log("药房药品统计")
    @ApiOperation("药房药品统计")
    @PostMapping("/findStatistics")
    public ResponseEntity<StoreDrugResp> findStatistics(@Validated StoreDrugRequest request) {
        request.setPharmacyId(LoginUserUtil.getPharmId());
        request.setEndTime(request.getEndTime() + " 23:59:59");
        request.setStartTime(request.getStartTime() + " 00:00:00");
        return ResponseEntity.ok(this.service.findStatistics(request));
    }

    @ApiOperation("数据导出")
    @PostMapping("/export")
    public void export(@Validated @RequestBody StoreDrugRequest request, HttpServletResponse response) throws IOException {
        request.setPharmacyId(LoginUserUtil.getPharmId());
        request.setEndTime(request.getEndTime() + " 23:59:59");
        request.setStartTime(request.getStartTime() + " 00:00:00");
        this.service.export(request, response);
    }

}
